/**  
* <p>Title: WeixinResult.java</p>  
* <p>Description: </p>  
* <p>Copyright: Copyright (c) 2018</p>  
* <p>Company: www.efastserv.com</p>  
* @author zhulin  
* @date 2018年6月4日  
* @version 1.0  
*/
package com.efast.cafe.portal.bean.common;

import com.alibaba.fastjson.JSONObject;

public class WeixinResult {

	private String result;

	private int ErrCode;

	private String ErrMsg;

	public WeixinResult() {
	}

	public WeixinResult(Exception ex)
    {
        this.ErrCode = -888;
        this.ErrMsg = ex.toString();
    }
	
	public WeixinResult(String ErrMsg, int ErrCode) {
		this.ErrCode = ErrCode;
		this.ErrMsg = ErrMsg;
	}

	public WeixinResult(JSONObject json) {
		if (json.containsKey("errcode") && !json.getString("errcode").isEmpty()) {
			ErrCode = json.getIntValue("errcode");

			if (json.containsKey("errmsg") && !json.getString("errmsg").isEmpty()) {
				ErrMsg = json.getString("errmsg");
			} else {
				ErrMsg = "";
			}
		}
	}

	public static WeixinResult Fail(String msg) {
		return new WeixinResult(msg, -888);
	}

	public static WeixinResult Success() {
		return new WeixinResult("success", 0);
	}

	public int getErrCode() {
		return ErrCode;
	}

	public void setErrCode(int errCode) {
		ErrCode = errCode;
	}

	public String getErrMsg() {
		return ErrMsg;
	}

	public void setErrMsg(String errMsg) {
		ErrMsg = errMsg;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

}
